package com.navinfo.platform.wbs.dto;


import lombok.Data;
import lombok.NoArgsConstructor;
import org.bson.Document;

import java.io.Serializable;
import java.sql.Date;
import java.sql.Timestamp;

@Data
@NoArgsConstructor
public class StatisticsBean implements Serializable {
    private long tid;
    private int status;
    private int times;
    private int count;
    private int duration;
    private int lastGpsDate;
    private int currDate;
    private boolean lastStatus;
    private Timestamp updateTime = new Timestamp(System.currentTimeMillis());

    public StatisticsBean(int status){
        this.status = status;
    }

    public StatisticsBean(long tid, int status){
        this.tid = tid;
        this.status = status;
    }

    public void clearData(){
        this.status = 0;
        this.tid = 0;
        this.times = 0;
    }

    public int getDiffDuration(){
        if(lastGpsDate == 0){
            return 0;
        } else {
            return currDate - lastGpsDate;
        }
    }

    public int calcDuration(int limit){
        if(lastGpsDate == 0){
            return 0;
        } else {
            return currDate - lastGpsDate > limit ? 0 : currDate - lastGpsDate;
        }
    }

    public void incrDuration(int duration){
        this.duration += duration;
    }


    public Document toDoc(){
        Document doc = new Document();
        doc.put("status",status);
        doc.put("duration", duration);
        doc.put("oilConsumption", 0D);
        doc.put("mileage", 0D);
        return doc;
    }
}


